package Call_3;



import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Random;

public class Call {
    public static void main(String[] args) throws IOException {
         Random r = new Random();
        ArrayList<Student> list=new ArrayList();
        BufferedReader br=new BufferedReader(new FileReader("namesboyandgils.txt"));
        String line;
        while((line=br.readLine())!=null){
            String[] arr = line.split("-");
            Student s= new Student(arr[0], arr[1], Integer.parseInt(arr[2]));
            list.add(s);
        }
        br.close();
        System.out.println(list);
        boolean exits = Files.exists(Paths.get("count_data.txt"));
        if(exits){
            BufferedReader br1=new BufferedReader(new FileReader("count_data.txt"));
            int count = Integer.parseInt(br1.readLine())+1;
            System.out.println("count:"+count);
            BufferedWriter bw=new BufferedWriter(new FileWriter("count_data.txt"));
            if(count<3){
                bw.write(count+"");
                int num = r.nextInt(list.size());
                System.out.println(list.get(num));
                bw.close();
            }else{
                bw.write("0");
                System.out.println("张三-男-28");// 可以指定一个人
                bw.close();
            }

        }else{
            BufferedWriter bw=new BufferedWriter(new FileWriter("count_data.txt"));
            bw.write("0");
            bw.close();
        }




    }
}
